﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EasyMvcBlog.Service;
using EasyMvcBlog.DTO;
using EasyMvcBlog.Domain;

namespace EasyMvcBlog.Controllers
{
    public class TagsController : Controller
    {
        /// <summary>
        /// 获得所有的tag标签
        /// </summary>
        /// <returns></returns>
        public JsonResult AllTags()
        {
            List<TagDTO> allTags = TagService.GetAllTags();
            return Json(allTags, JsonRequestBehavior.AllowGet);
        }

        public ActionResult ManageTags(int? id)
        {
            int pageIndex = 1;

            if (id != null && id > 0)
            {
                pageIndex = (int)id;
            }

            TagDomain tagDomain = new TagDomain();
            List<TagDTO> tags = tagDomain.GetTagsByPage(pageIndex, 20);
            return View(tags);
        }

        public JsonResult DeleteTag(int tagId)
        {
            TagDomain tagDomain = new TagDomain();
            return Json(tagDomain.DeleteTag(tagId));
        }
    }
}
